<?php
namespace app\common\library;

/**
 * Class CategoryType
 * @package app\common\library
 * Author: LCY<409028735@qq.com>
 * Time: 2021/12/23 11:47
 * Note:分类类型
 */
class CategoryType {
    /**
     * @var array
     * 分类类型配置
     */
    protected static $config = [
        [
            'title' => '广告位',
            'key'   =>  'banners',
            'icon'   =>  'bi bi-justify-left fs-4 me-1',
            'max_depth' => 1,
        ],
        [
            'title' => '新闻资讯',  //分类类型名称
            'key'   =>  'news', //唯一标识
            'icon'   =>  'bi bi-justify-left fs-4 me-1', //图标
            'max_depth' => 1, //该类型下的分类允许添加的最大层级
        ]
    ];

    /**
     * 获取所有的分类类型
     * @return array
     * Author: LCY<409028735@qq.com>
     * Time: 2021/12/23 11:50
     * Note:
     */
    public static function getAllType()
    {
        return self::$config ? : [];
    }

    /**
     * 获取该分类类型允许的最大层级
     * @param $key
     * @return int
     * Author: LCY<409028735@qq.com>
     * Time: 2021/12/23 11:53
     * Note:
     */
    public static function getTypeMaxDepth($key)
    {
        $max_depth = 1000;
        foreach (self::getAllType() as $type) {
            if($type['key'] == $key) {
                $max_depth =  $type['max_depth'] ? : $max_depth;
                break;
            }
        }

        return $max_depth;
    }

}